<?php
namespace App\Http\Requests\System\User;

use App\Http\Requests\Request;

class ItemRequest extends Request
{

    /**
     * 应用于请求的验证规则。
     *
     * @return array
     */
    public function rules()
    {
        $user = $this->user();

        return [
            'id' => 'nullable|integer|min:1',
            'is_super_admin' => 'nullable|integer|in:0,1',
            'name' => 'required|string|between:2,32',
            'email' => 'required|string|email|max:128',
            'password' => ['nullable', 'required_without:id', 'string', 'between:8,16', 'letters', 'case_diff', 'numbers', 'symbols',
                function ($attribute, $password, $fail) use ($user) {
                    if ($user->email == $password) {
                        $fail(trans('validation.pwd_email_diff'));
                    }
                }
            ],
        ];
    }

    /**
     * 自定义验证规则的错误消息。
     *
     * @return array
     */
    public function messages()
    {
        return [
            'password.required_without' => trans('validation.required')
        ];
    }

    /**
     * 自定义字段名称。
     *
     * @return array
     */
    public function attributes()
    {
        return [];
    }
}
